package com.bzkj.web.controller.warehouse;

import com.bzkj.basicinfo.domain.ncc.BasicStoShelf;
import com.bzkj.basicinfo.service.ncc.BasicStoShelfService;
import com.bzkj.common.annotation.LogC;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.domain.R;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/basicStoShelf")
public class BasicStoShelfController extends BaseController
{
    @Autowired
    private BasicStoShelfService basicStoShelfService;


    @PostMapping
    @LogC(title = "货位类型", businessType = BusinessType.INSERT, pkFieldNames = "id",
            tableNames = "basic_sto_shelf", content = "'货位类型名称：'+#basicStoShelf.name"
    )
    public AjaxResult addWarehouse(@RequestBody BasicStoShelf basicStoShelf)
    {
        return basicStoShelfService.addBasicStoShelf(basicStoShelf);
    }

    @PutMapping
    @LogC(title = "货位类型", businessType = BusinessType.UPDATE, pkFieldNames = "id",
            tableNames = "basic_sto_shelf",content = "'类型名称：'+#basicStoShelf.name"
    )
    public AjaxResult updateWarehouse(@RequestBody BasicStoShelf basicStoShelf)
    {
        int result = basicStoShelfService.updateBasicStoShelf(basicStoShelf);
        if (result > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }

    @DeleteMapping("/{id}")
    @LogC(title = "货位类型", businessType = BusinessType.INVALID, pkFieldNames = "id",
            tableNames = "basic_sto_shelf", content = "'货位类型id：'+#id"
    )
    public AjaxResult deleteBasicStoShelf(@PathVariable Integer id)
    {
        int result = basicStoShelfService.deleteBasicStoShelf(id);
        if (result > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }

    @GetMapping("/{id}")
    public AjaxResult getBasicStoShelf(@PathVariable Integer id)
    {
        return AjaxResult.success(basicStoShelfService.getBasicStoShelf(id));
    }

    @GetMapping
    public TableDataInfo getAllBasicStoShelf(BasicStoShelf basicStoShelf)
    {
        startPage();
        List<BasicStoShelf> basicStoShelves = basicStoShelfService.getAllBasicStoShelf(basicStoShelf);
        return getDataTable(basicStoShelves);
    }
    @GetMapping("/unit")
    public TableDataInfo getAllBasicStoUnit(BasicStoShelf basicStoShelf)
    {
        startPage();
        List<BasicStoShelf> basicStoShelves = basicStoShelfService.getAllBasicStoUnit(basicStoShelf);
        return getDataTable(basicStoShelves);
    }

    @GetMapping("all")
    public R getAll()
    {
        List<BasicStoShelf> shelf = basicStoShelfService.getAllBasicStoShelf(null);
        R<List<BasicStoShelf>> ok = R.ok();
        ok.setData(shelf);
        return ok;
    }
}
